1. Field of the Invention
The present invention relates to rendering apparatus (engine), rendering processing method and computer program product, which carry out rendering processing of a three-dimensional computer graphics (three-dimensional (3-D) CG) image. In particular, the present invention relates to rasterizing if rendering primitive includes a segment having a vertex existing backwardly from the viewpoint.
2. Description of the Related Art
Three-dimensional CG is a technique of representing and arranging various objects in a computer virtual three-dimensional space by modeling, and drawing how these objects are seen from viewpoints set in the space in a two-dimensional screen.
In particular, the technique of drawing objects in the two-dimensional screen calls rendering. The rendering includes various processings described below. Specifically, the processings are setting of viewpoint and light source, predetermined coordinate transformation, hidden-surface elimination, shadowing, viewport conversion, anti-aliasing, etc. A processor (engine), which carries out the foregoing rendering at high speed and drawing an image in real time, calls a real-time CG processor (engine).
According to the foregoing rendering, it must be determined whether or not a pixel to be drawn exists inside rendering primitive. Thus, in order to express the shape of the rendering primitive with a linear function couple, the following calculation is made.
For example, if rendering primitive is a triangle, the shape of the triangle is expressed using three linear functions shown in the following equation (1).A0(X, Y)=a0×(X·X0)+b0×(Y·Y0)A1(X, Y)=a1×(X·X1)+b1×(Y·Y1)A2(X, Y)=a2×(X·X2)+b0×(Y·Y2)  (1)
Where
(X, Y): pixel window coordinate (i.e., coordinate on two-dimensional coordinate system set in viewport
(X0, Y0), (X1, Y1), (X2, Y2): window coordinate of the vertex of the triangle
a0, b0, a1, b1, a2, b2: constant
The foregoing linear functions call an edge function, and the pixel on a viewport (graphic area) is classified into three areas, that is, inside, side and outside of the triangle. In this case, the pixel having an edge function value larger than 0 means that it exists inside the triangle. The pixel having an edge function value equal to 0 means that it exists on the side of the triangle. The pixel having an edge function value smaller than 0 implies that it exists outside the triangle.
Therefore, in rasterizing, it is determined whether or not the edge function values on three sides are all large than 0. By doing so, it is determined whether or not the pixel exists inside the triangle. Incidentally, coefficients a0, b0, a1, b1, a2 and b2 are calculated using the following equation (2).a0=Y0·Y1b0=X1·X0a1=Y1·Y2b1=X2·X1a2=Y2·Y0b2=X0·Y2  (2)
In this case, the vertex (X0, Y0), (X1, Y1), (X2, Y2) of the triangle is arranged on the viewport in the counterclockwise direction.
In order to load the foregoing calculation procedures to hardware, a method calling DDA (Digital Differential Analysis) is often employed. According to the DDA, only initial value of the edge function in a start pixel is calculated using the equation (1). The foregoing coefficients a0, b0, a1, b1, a2 and b2 of the edge function are successively added to the initial value. In this manner, edge function values of neighboring pixels are obtained. Moreover, the DDA is often used for the procedure of interpolating a vertex parameter to calculate a pixel parameter. The contents of the DDA are as follows.
First, a parameter initial value in the start pixel (X, Y) is calculated using the following parameter function equation (3).P(X, Y)=a×X+b×Y+c  (3)
Where,
(X, Y): window coordinate of pixel
a, b and c: coefficient of parameter function
If the rendering primitive is a triangle, the following simultaneous linear equation (4) is solved to calculate the foregoing coefficients a, b and c.a×X0+b×Y0+c=p0a×X1+b×Y1+c=p1a×X2+b×Y2+c=p2  (4)
Where,
(X0, Y0), (X1, Y1), (X2, Y2): window coordinate of the vertex of the triangle
p0, p1, p2: parameter value representing arbitrary attribute of the corresponding vertex
In this case, the foregoing coefficients a, b and c must be calculated every kind of parameter.
According the DDA, the coefficients a and b calculated by the equation (4) are added to the initial value calculated by the equation (3), thereby obtaining parameters of neighboring pixels. The calculations described above are made, and thereby, the following processings are carried out. One is determination whether or not the pixel exists inside rendering primitive. Another is interpolation of interpolating the vertex parameter to obtain pixel parameter.
In order to effectively achieve the foregoing determination and interpolation, it is important to select processing target pixel without waste as much as possible. Thus, some methods of effectively scanning the processing target pixel have been proposed.
The most popular method is a method of scanning the processing target pixel every rectangular area calling a stamp. The stamp is a rectangular area where pixels parallel-processed at one cycle in rasterizing are collected. For example, the stamp size is 8×8 pixels as seen from FIG. 13 disclosed in JPN. PAT. APPLN. KOAKI Publication No. 2003-423797. In this case, 64 pixels are parallel-processed for one cycle in rasterizing, and moved every cycle to scan the viewport, thereby generating pixel data.
FIG. 26-1 of JPN. PAT. APPLN. KOAKI Publication No. 2003-423797, there is shown the procedure of scanning a triangle rendering primitive using a rectangular stamp. As seen from FIG. 26-1, the stamp is moved on the line along the X-axis direction of viewport to perform one-line scanning. The line scanning is completed, and thereafter, the stamp is moved to the Y-axis direction so that it is moved along the next line. The foregoing operation is successively repeated, and thereby, pixel data is generated.
If the rendering primitive is a segment, the segment is expanded by d pixel in a minor axis direction to form a parallelogram, and thereafter, the formed parallelogram is scanned. The minor axis means a shorter axis of X-axis and Y-axis after the segment is projected; on the contrary, a longer axis calls a major axis. The foregoing “d” value is usually set to 1.0; in this case, the value is made large, and thereby, a thin segment is drawn. The parallelogram is scanned every stamp like the case of the triangle. By doing so, the following processings are carried out. One is determination whether or not the pixel exists inside the parallelogram. Another is interpolation of interpolating the vertex parameter to obtain pixel parameter.
The conventional determination and interpolation described above are carried out using the following coordinate (window coordinate). The coordinate (window coordinate) is obtained in a manner of projecting the vertex of rendering primitive in a modeled three-dimensional coordinate system on the window.
However, if the rendering primitive includes a vertex existing backwardly from the viewpoint, the vertex is not projected on the window; as a result, it does not have window coordinate. In general, the following processings are required to rasterize the foregoing rendering primitive. Specifically, as seen from FIG. 21 and FIG. 22 (of JPN. PAT. APPLN. KOAKI Publication No. 2003-423797), the rendering primitive is previously cut along neighboring clip plane. The rendering primitive is divided into part, which is projected on the viewport and part, which is not projected on there. Then, the foregoing determination and interpolation are carried out using part projected on the viewport only.
The foregoing processing of dividing the rendering primitive along the clip surface calls clipping. The clipping is complicated, and much processings are required. For this reason, dedicated hardware is frequently required; as a result, there is a possibility that the cost becomes high. For example, some rasterizing methods of requiring no clipping have been proposed as a technique of solving the foregoing problem. The method is disclosed in U.S. Pat. No. 6,504,542, Marc Olano and Trey Greer, “Triangle Scan Conversion using 2D Homogeneous Coordinates”, 1997, SIGGRAPH/Euro-graphics Workshop In order to carry out the foregoing rasterizing methods requiring no clipping, a method of effectively searching a scan start point is newly required. The inventors have proposed a technique disclosed in JPN. PAT. APPLN. KOAKI Publication No. 2003-423797. According to the technique, a triangle projection image including a vertex existing backwardly from the viewpoint is classified using the vertex homogeneous coordinate. In accordance with the classified result, the scan start point is determined.
However, the foregoing technique is provided on the assumption that the rendering primitive is a triangle; for this reason, other rendering primitives such as segments are not taken into consideration.